﻿
@{ ViewData["Title"] = "QQ用户列表"; }
<blockquote class="layui-elem-quote quoteBox">
    <div class="layui-inline">
        <div class="layui-input-inline">
            <input type="text" name="NikeName" data-op="cn" class="layui-input searchVal" placeholder="请输入昵称" />
        </div>
        <a class="layui-btn search_btn" data-type="reload">搜索</a>
    </div>
    <div></div>
</blockquote>

<table id="laytable" lay-filter="qqList"></table>
@section script{
    <script type="text/javascript">
        layui.use(['tools', 'laytpl'], function () {
            var $ = layui.$, table = layui.table, tools = layui.tools, form = layui.form, total = 0;

            table.render({
                elem: '#laytable',
                url: '/BlogManage/QQUser/Index',
                method: 'post',
                toolbar: '#toolsHead',
                loading: true,
                height: "full-125",
                limit: 15,
                limits: [10, 15, 20, 25, 30, 35, 40, 45, 50],
                page: true,
                where: { order: 'CreatorTime asc' },
                cols: [[
                    { type: 'numbers' },
                    { field: 'NikeName', title: '昵称' },
                    { field: 'Gender', title: '性别' },
                    {
                        field: 'EnabledMark', title: '身份', templet: function (d) {
                            return '<input type="checkbox" name="enabled" lay-filter="enabled" lay-skin="switch" key="' + d.Id + '" lay-text="博主|用户" ' + (d.IsMaster ? 'checked' : '') + '>'
                        }
                    },
                    { field: 'Birthday', title: '生日' },
                    { field: 'Province', title: '省份' },
                    { field: 'LastLoginTime', title: '最后登录日期', sort: true },
                    { field: 'CreatorTime', title: '注册日期', sort: true },
                    { title: '操作', fixed: 'right', align: 'center', hide: rowButton.length == 0, width: rowButton.length * 80, templet: '#toolsRow' }
                ]],
                done: function (res, curr, count) {
                    total = count;
                }
            });

            table.on('tool(qqList)', function (obj) {
                var url = $(this).data("url"), layEvent = obj.event;
                active[layEvent](url, obj.data.TagId);
            });

            table.on('toolbar(qqList)', function (obj) {
                var url = $(this).data("url");
                var layEvent = obj.event;
                active[layEvent](url);
            });

            table.on('sort(qqList)', function (obj) {
                table.reload("laytable",
                    {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        },
                        where: {
                            //排序字段
                            order: obj.field + " " + obj.type //排序方式

                        }
                    });
            });

            form.on('switch(enabled)', function (data) {
                var _this = $(this), s = data.elem.checked;
                tools.submitConfrim({
                    prompt: "您确定将用户" + (s ? "设置为" : "取消") + "博主吗？",
                    url: "/BlogManage/QQUser/Master",
                    data: { key: _this.attr("key"), status: s },
                    cancelCallBack: true,
                    success: function (result) {
                        if (result.StatusCode === 200) {
                            _this.prop('checked', s);
                        } else {
                            _this.prop('checked', !s);
                        }
                        form.render("checkbox");
                    }, cancel: function () {
                        _this.prop('checked', !s);
                        form.render("checkbox");
                    }
                });
            });

            $(".search_btn").click(function () {
                table.reload("laytable", {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: tools.condition()
                });
            });

            var active = {
                delete: function (url, id) {
                    tools.submitConfrim({
                        prompt: "您确定需要删除当前用户吗？",
                        url: url,
                        data: { key: id },
                        success: function () {
                            table.reload("laytable");//重新加载
                        }
                    });
                }
            };
        });
    </script>
}
